package com.lx.testdemo;

import java.util.Arrays;
import java.util.Comparator;

public class test {
    public static void main(String[] args) {
        girlfriend g1 = new girlfriend("lisi",20,177.5);
        girlfriend g2 = new girlfriend("zhangsan",23,177.2);
        girlfriend g3 = new girlfriend("wangwu",22,175.4);
        girlfriend arr[] = {g1,g2,g3};
        Arrays.sort(arr, new Comparator<girlfriend>() {
            @Override
            public int compare(girlfriend o1, girlfriend o2) {
                double temp = o1.getHeight() - o2.getHeight();
                temp = temp == 0?o1.getAge()-o2.getAge():temp;
                temp = temp == 0?o1.getName().compareTo(o2.getName()):temp;
                if(temp==0)
                {
                    return 0;
                }
                else if(temp>0)
                {
                    return 1;
                }
                else {
                    return -1;
                }
            }
        });
        System.out.println(Arrays.toString(arr));
    }
}
